Add two numbers
num1 = 10
num2 = 20
sum = num1 + num2
print("Sum of {0} and {1} is {2}" .format(num1, num2, sum))
Adding two number provided by user input
# Python3 program to add two numbers
number1 = input("First number: ")
number2 = input("\nSecond number: ")
sum = float(number1) + float(number2)
print("The sum of {0} and {1} is {2}" .format(number1, number2, sum))
Find the sum of an element of List
# creating a list
list1 = [11, 5, 17, 18, 23,10]
num= len(list1)
total=0
for i in range(0,num):
total=total+list1[i]
# printing total value
print("Sum of all elements in given list: ", total)
Python Program to count the occurrence of vowel in the given string
string = "Python is a programming Language"
vowels = "aeiou"
counts = {}
for char in string:
if char.lower() in vowels:
if char.lower() not in counts:
counts[char.lower()] = 1
else:
counts[char.lower()] += 1
print("The counts of vowels in the string are:")
print(counts)
for vowel, count in counts.items():
print(vowel, ": ", count)
Python Program to count the number of lowercase characters and uppercase characters in a string.
def count_upper_lower(string):
count1=0
count2=0
for i in string:
if i.isupper():
count1 += 1
elif i.islower():
count2 += 1
return count1,count2
string="Hello How are you"
count1,count2 = count_upper_lower(string)
print(len(string))
print(f"Uppercase count : {count1}")
print(f"Uppercase count : {count2}")
No comments:
Post a Comment